<?php
/**
 * receiver.php
 * Script to receive images via POST
 *
 * $Id: receiver.php 65 2007-09-22 01:02:43Z jonathan.hernandez $
 */
require_once "config/config.php";
require_once "include/FooModel.php";

// Check parameters
if (!isset($_POST['username']) ||
    !isset($_POST['password']) ||
    !isset($_POST['sender']) ||
    !isset($_FILES['file'])) {
    header('HTTP/1.0 400 Bad Request');
    exit;
}

$fv = new FooModel($conf);

// TODO: User and password must be provided by some auth method (credentials)
$username  = $_POST['username']; 
$password  = $_POST['password'];
$sender    = $_POST['sender'];
$imagename = isset($_POST['imagename'])?$_POST['imagename']:'';
try {
    if ($fv->receiveImage($username, $password, $sender, $imagename, $_FILES['file'])) {
        header('HTTP/1.0 200 OK');
        exit;
    } else {
        header('HTTP/1.0 400 Bad Request');
        exit;
    }
} catch (Exception $e) {
    header('HTTP/1.0 400 Bad Request');
    exit;
}
